<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>示例11</title>
    <script>
        const promise = new Promise(function (resolve, reject) {
            // 使用 setTimeout 模拟异步操作 
            setTimeout(() => {
                let result = true;
                // 假设异步操作结果拿到新闻列表 
                let value = [{
                    title: "标题 1",
                    content: "内容 1"
                }];
                let error = "失败信息";
                if (result) {
                    // 异步操作成功 
                    resolve(value);
                } else {
                    // 异步操作失败 
                    reject(error);
                }
            }, 3000);
        });
        console.log("new promise", promise);
        promise.then(function (value) {
            console.log("then promise", promise);
            // 异步操作成功 
            console.log("then value", value);
        }, function (error) {
            console.log("error promise", promise);
            // 异步操作失败 
            console.log("error value", error);
        })
    </script>
</head>

<body></body>

</html>